/**cc组件类装饰器  见 
 * https://docs.cocos.com/creator/manual/zh/scripting/decorator.html 
*/
import { _decorator, Camera, Component, Event, EventMouse, Input, input, Node, NodeEventType, System, UITransform, v2, v3 } from 'cc';
const { ccclass, property } = _decorator;

/**一些常用默认操作 
 * 右键拖拽屏幕
*/
@ccclass('default_operate')
export class default_operate extends Component {

    @property(Camera)
    camera: Camera = null;

    start() {
        // 右键拖拽屏幕
        input.on(Input.EventType.MOUSE_MOVE, this.onMouseMove,this);
        //监听鼠标滑轮
        input.on(Input.EventType.MOUSE_WHEEL, this.onMouseWheel, this);
        console.log("default_operate start");
    }

    onMouseMove(e) {
        
        if (e.getButton() == 2) {
            // console.log("event:::",typeof e);
            // console.log(e.getDelta());
            let v_3 = v3(this.camera.node.position.x - e.getDeltaX(), this.camera.node.position.y - e.getDeltaY(),this.camera.node.position.z);
            // console.log("v_3::",v_3.toString())
            this.camera.node.setPosition(v_3);
        }

        if(e.getButton() == 1){//复原   
            this.camera.orthoHeight = 387;
            this.camera.node.position = v3(0,0,1000);
        }

    }
    onMouseWheel(e:EventMouse) {
        // console.log("onMouseWheel  e::",e);
        let wheel_socreY = e.getScrollY();//往前滚是正 往后滚是负  logitech牌子的鼠标，一次滚轮滚动是500，嗯，这个值是固定的
        // 设置一个滚动比例 调整相机otho值
        let roll_val = wheel_socreY / 500 * 10;
        this.camera.orthoHeight -= roll_val;
    }

    

}



